package com.terrapages.wmsc4j.utils;


import com.terrapages.wmsc4j.WMSC;
import com.terrapages.wmsc4j.bean.BBox;
import com.terrapages.wmsc4j.layer.AbstractLayer;
import com.terrapages.wmsc4j.layer.resolution.Resolution;
import com.terrapages.wmsc4j.layer.tile.Tile;
import com.terrapages.wmsc4j.wms.InvalidWMSParameterException;
import com.terrapages.wmsc4j.wms.WMSParameters;

/**
 * Class to get Maps
 * 
 * @author mvivian
 */
public class GetMap{

	private static final long serialVersionUID = 1L;
	
	
	public static Tile getTile(final AbstractLayer layer, BBox bbox){
		Resolution resolution = layer.getResolution(layer.getZoomLevel(new Resolution(bbox,layer.getFormat().getTileSize())));
		Tile retTile = new Tile(layer,bbox.getCentrePos(),resolution);
		layer.getTile(retTile);
		return retTile;
	}
	
	public static Tile getTile(WMSC wmsc, WMSParameters params) throws InvalidWMSParameterException {
		BBox bbox = params.getBoundingBox();
		AbstractLayer layer = wmsc.getLayer(params.getLayers());
		Tile retTile = null;
		if(layer != null)
		{
			retTile = getTile(layer,bbox);
		}
		return retTile;
	}
}
